<template>
	<view class="content">
		<view v-if="list.length > 0" class="income-list">
			<view class="income-item" v-for="item in list" :key="item.id">
				<view class="item-header">
					<text class="time">{{item.updated_at}}</text>
				</view>
				<view class="item-content">
					<image class="income-icon" src="../../static/img/ahi_icon.png" mode=""></image>
					<view class="income-info">
						<text class="card">账户：{{item.card}}</text>
						<text class="money">金额：{{item.money}}</text>
						<text class="desc">备注：{{item.description}}</text>
					</view>
					<view class="income-status">
						<text class="status">{{item.status | getStatus}}</text>
					</view>
				</view>
			</view>
		</view>
		<view v-else class="empty-wrap">
			<image class="empty-icon" src="../../static/img/empty.png" mode=""></image>
			<text class="empty-text">暂无提现记录</text>
		</view>
		<uni-load-more :status="status" :content-text="contentText"></uni-load-more>
	</view>
</template>

<script>
	import uniLoadMore from "@/components/uni-load-more/uni-load-more.vue";
	export default {
		components: {
			uniLoadMore
		},
		data() {
			return {
				myInfo: {},
				list: [],
				page: 1,
				status: 'more',
				contentText: {
					contentdown: '加载更多',
					contentrefresh: '加载中',
					contentnomore: '木有了~'
				},
			}
		},
		onLoad(options) {
			try {
				const myInfo = uni.getStorageSync('myInfo');
				if (myInfo) {
					this.myInfo = myInfo;
				}
			} catch (e) {
				console.log(e)
			}
		},
		onReady() {
			this.getUserCashoutList();
		},
		onPullDownRefresh() {
			this.page = 1;
			setTimeout(() => {
				this.getUserCashoutList();
			}, 500)
		},
		onReachBottom() {
			this.status = 'loading';
			this.getUserCashoutList();
		},
		methods: {
			getUserCashoutList: function () {
				this.$api.api.ajaxData({
					method: 'V1.UserCashoutList',
					uid: this.myInfo.id,
					token: this.myInfo.token,
					page: this.page
				}, res => {
					uni.stopPullDownRefresh();
					if (res.status) {
						if (this.page == 1) {
							this.list = res.data.list.data
							this.page++
							this.status = 'more'
						} else {
							if (res.data.list.data.length > 0) {
								for (let i = 0; i < res.data.list.data.length; i++) {
									this.list.push(res.data.list.data[i])
								}
								this.page++
								this.status = 'more'
							} else {
								this.status = 'noMore'
							}
						}
					}
				})
			},
		},
		filters: {
			getStatus(value) {
				if (value == '0') {
					return '已申请';
				}
				if (value == '1') {
					return '完成';
				}
				if (value == '2') {
					return '拒绝';
				}
				if (value == '3') {
					return '异常';
				}
			}
		}
	}
</script>

<style lang="scss">
	@import '../../common/common.scss';
	.income-item {
		padding: 0 20rpx;
		margin-bottom: 1rpx;
		background-color: #FFFFFF;
		.item-header {
			padding: 20rpx;
			border-bottom: 1rpx solid $border-light-color;
			.time {
				font-size: 28rpx;
				color: $text-color;
			}
		}
		.item-content {
			display: flex;
			justify-content: flex-start;
			align-items: center;
			padding: 20rpx;
		}
		.income-icon {
			width: 80rpx;
			height: 80rpx;
			margin-right: 20rpx;
		}
		.income-info {
			display: flex;
			flex-direction: column;
			justify-content: flex-start;
			align-items: flex-start;
			flex: 1;
			.card {
				font-size: 28rpx;
				color: $title-color;
			}
			.money {
				font-size: 28rpx;
				color: $title-color;
			}
			.desc {
				font-size: 28rpx;
				color: $text-color;
			}
		}
		.income-status {
			margin-left: 20rpx;
			text {
				font-size: 32rpx;
				color: $title-color;
			}
		}
	}
</style>
